package src.pta07;
import java.util.Scanner;
class Repo{
	String[] str;
	static boolean flag1 = true;
	static boolean flag2 = true;
	
	public Repo(String items) {
		str = items.split(" ");
	}
	int getSize(){
		int size = 0;
		for (int i = 0; i < str.length; i++) {
			if(str[i] != null)
				size++;
		}
		return size;
	}
	public synchronized String delTask(){
		String temp = str[0];
		for (int i = 0; i < str.length - 1; i++) {
			this.str[i] = this.str[i +1 ];
		}
		this.str[str.length - 1] = null;
		return temp;
	}
}
class Worker1 implements Runnable{
	private Repo repo;
	public Worker1(Repo repo){
		this.repo = repo;
	}
	@Override
	public  void run() {
		while(repo.getSize() != 0){
			if(Repo.flag1 == true){
				System.out.println(Thread.currentThread().getName()+ " finish " + repo.delTask());
				Repo.flag1 = false;
				Repo.flag2 = true;
			}
		}
	}
}
class Worker2  implements Runnable{
	private Repo repo;
	public Worker2(Repo repo){
		this.repo = repo;
	}
	@Override
	public void run() {
		while(repo.getSize() != 0){
			if(Repo.flag2 == true){
				System.out.println(Thread.currentThread().getName()+ " finish " + repo.delTask());
				 Repo.flag2 = false;
				 Repo.flag1 = true;
			}
		}
	}
}
public class Main06 {

	 public static void main(String[] args) throws InterruptedException {
	        Scanner sc = new Scanner(System.in);
	        Repo repo = new Repo(sc.nextLine());
	        Thread t1 = new Thread(new Worker1(repo));
	        Thread t2 = new Thread(new Worker2(repo));
	        t1.start();
	        Thread.yield();
	        t2.start();
	        sc.close();
	    }
	}